package cn.zhz.office.convert.word.controller;

import cn.zhz.office.convert.word.util.WordConvertUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ZHZ
 * @since 2023-01-30
 */
@RestController
@RequestMapping("/word")
public class WordController {


    @PostMapping("/toPdf")
    public void toPdf(@RequestParam MultipartFile file, HttpServletResponse response) throws IOException {
        WordConvertUtil.toPdf(file.getInputStream(), response.getOutputStream());
    }

    @PostMapping("/toHtml")
    public void toHtml(@RequestParam MultipartFile file, HttpServletResponse response) throws IOException {
        WordConvertUtil.toHtml(file.getInputStream(), response.getOutputStream());
    }

    @PostMapping("/toImage")
    public void toImage(@RequestParam MultipartFile file, HttpServletResponse response) throws IOException {
        WordConvertUtil.toImage(file.getInputStream(), response.getOutputStream());
    }

}
